using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace Report.PhieuD
{
    public partial class UcD103 : DevExpress.XtraEditors.XtraUserControl
    {
        public UcD103()
        {
            InitializeComponent();
        }

        private void UcD103_Load(object sender, EventArgs e)
        {
            DataTable dtD103 = new DsReportX.Table7ColDataTable();
            dtD103 = CalculateData(dtD103);
            gridControlA.DataSource = dtD103;
        }
        DataTable CalculateData(DataTable dt)
        {
            SqlConnection con = new SqlConnection(GeneralLibs.LocalSettings.ConnectString);
            SqlCommand cmd = con.CreateCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                con.Open();
                cmd.CommandText = "SELECT SUM(Number1) Number1,  SUM(Number2) Number2, SUM(Number3) Number3, SUM(Number4) Number4 \n" +
                                "FROM Phieu_DangBang A INNER JOIN Phieu B ON A.PhieuID = B.ID \n" +   
                                "WHERE B.LoaiPhieu = 'PhieuD' AND MaCau = 14 \n" +
                                "GROUP BY ThuTuTrongBang \n" + 
                                "ORDER BY ThuTuTrongBang ";


                da.SelectCommand = cmd;
                da.Fill(dt);

                return dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
            finally
            {
                con.Close();
            }
        }
    }
}
